package com.controller.yxy;

import com.alipay.api.AlipayApiException;
import com.bean.yxy.AlipayBean;
import com.bean.yxy.AlipayResponse;
import com.service.yxyService.GetDataService;
import com.util.alicloud.alipay.AliPay;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller
public class AliPayController {
    @Resource
    private HttpSession session;

    @Autowired
    private GetDataService getDataService;

    @RequestMapping(value = "alipay",method = RequestMethod.GET)
    @ResponseBody
    public AlipayResponse alipayPage( AlipayBean alipayBean ,HttpServletResponse resp){
           AliPay ap = new AliPay();
           session.setAttribute("zhifbao",alipayBean.getVid());
        AlipayResponse ar = new AlipayResponse();
        try {
            String alipayPageString = ap.pay(alipayBean);
            ar.setPageHtml(alipayPageString);
        }catch (AlipayApiException e){
            e.printStackTrace();
        }
        return ar;
    }

    @RequestMapping(value = "shanchudid",method = RequestMethod.GET)
    public String shanchudid(){
        String vid =(String)session.getAttribute("zhifbao");
       boolean b= (boolean) getDataService.jieshuan(vid);
        System.out.println("---------");
        System.out.println(b);
       if(b){
           return "index.html";
       }
           return "index.html";
    }
}
